import {
  Entity,
  PrimaryColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  PrimaryGeneratedColumn,
  ManyToOne,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { User } from './User';
import { Tags } from './Tags';
@Entity({ name: 'posts' })
export class Posts {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: '主键id',
  })
  id: number;
  @Column({
    type: 'varchar',
    nullable: false,
    length: 50,
    unique: true,
    name: 'title',
    comment: '标题',
  })
  title: string;
  @Column({
    type: 'text',
    nullable: true,
    name: 'content',
    comment: '内容',
  })
  content: string;
  @Column('tinyint', {
    nullable: false,
    default: () => 0,
    name: 'is_del',
    comment: '是否删除，1表示删除 0表示正常',
  })
  is_del: number;
  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'created_at',
    comment: '创建时间',
  })
  created_at: Date;
  @UpdateDateColumn({
    type: 'timestamp',
    nullable: false,
    name: 'updated_at',
    comment: '更新时间',
  })
  updated_at: Date;
  // 和user表关联
  @ManyToOne(
    type => User,
    user => user.posts,
  )
  user: User;
  @ManyToMany(
    type => Tags,
    tag => tag.posts,
  )
  tags: Tags[];
}
